//局部作用域 避免命名冲突
(function () {
    let position = 'absolute';
    let food;
    function Food(parent, options) {
        options = options || {};
        this.parent = parent;
        this.x = options.x || 0;
        this.y = options.y || 0;
        this.color = options.color || 'red';
        this.width = options.width || 40;
        this.height = options.height ||40;
    }
    Food.prototype.render = function (map) {
        if (food) {
            map.removeChild(food)
        }
        let r = Tools.getRandom(0,255);
        let g = Tools.getRandom(0,255);
        let b = Tools.getRandom(0,255);
        this.color = 'rgb('+r+','+g+','+b+')';
        this.x = Tools.getRandom(0,map.offsetWidth/this.width-1);
        this.y = Tools.getRandom(0,map.offsetHeight/this.height-1);
        let div = document.createElement('span');
        div.style.display = 'inline-block';
        div.width = 40;
        div.height = 40;
        div.style.color = 'white';
        div.style.textAlign = 'center';
        div.innerText = '$';
        map.appendChild(div);
        food = div;
        div.style.left = this.x*this.width+'px';
        div.style.top = this.y*this.height+'px';
        div.style.position = position;
        div.style.width = this.width+'px';
        div.style.height = this.height+'px';
        div.style.backgroundColor = this.color;
        div.style.borderRadius = 40+'px'
    };

    window.Food = Food;
})();
